<?php

namespace app\components;

use Yii;

/**
 * Description of Lcms
 *
 * @author shuai
 */
class Lcms {

    const WEB_open = '1'; ///表示网站是否打开和关闭
    const WEB_close = '0';

    public static function getVersion() {
        return '5.0';
    }

    static $LOGO='/public/h5/images/icon.png';

    public static function getName() {
        return '美策';
    }

    public static function flush() {
        //

        Yii::$app->cache->flush();
        /// Yii::app()->cache->flush();
    }
 

 

    /**
     * 解密
     */
    public static function decrypt(){
        if(empty(Yii::$app->request->post('str'))){
            return false;
        }
        $str=Yii::$app->request->post('str');
        $mp = new PhpAes;
        $mw = $mp->AesDecrypt($str);
      ////  echo $mw."\r\n";
        $mw=base64_decode($mw);
         if(empty($mw)){
             return false;
         }
        $mw=self::unescape($mw);
        $json=  json_decode($mw,true);
        foreach ($json as $key=>$vo) {
            $_POST[$key]=$vo;
        } 
        return true;
    }
   public static function unescape($str) {
   $ret = '';  
    $len = strlen ( $str );  
    for($i = 0; $i < $len; $i ++) {  
        if ($str [$i] == '%' && $str [$i + 1] == 'u') {  
            $val = hexdec ( substr ( $str, $i + 2, 4 ) );  
            if ($val < 0x7f)  
                $ret .= chr ( $val );  
            else if ($val < 0x800)  
                $ret .= chr ( 0xc0 | ($val >> 6) ) . chr ( 0x80 | ($val & 0x3f) );  
            else  
                $ret .= chr ( 0xe0 | ($val >> 12) ) . chr ( 0x80 | (($val >> 6) & 0x3f) ) . chr ( 0x80 | ($val & 0x3f) );  
            $i += 5;  
        } else if ($str [$i] == '%') {  
            $ret .= urldecode ( substr ( $str, $i, 3 ) );  
            $i += 2;  
        } else  
            $ret .= $str [$i];  
    }  
    return $ret;  
}  

 
    /**
     * 网站目录
     */
   // static $getWeb='/halloween/';
    /// static $getWeb = '/biaoqingbao/index/';
    /**
     * 网站资源的目录
*/
    static function getWeb(){
        return Yii::getAlias('@web/');
    }

    /**
     * 网站域名
     */
    static function getHost(){
     //   return 'http://test.fuzhuangchangongxiao.cn';
        return 'http://'.$_SERVER['HTTP_HOST'];
    }

}
